package com.hfkh.keyun.controller.backend;

import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.AboutUs;
import com.hfkh.keyun.service.AboutUsService;
import com.hfkh.keyun.vo.AboutUsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: jhh
 */
@RestController
@Api(tags = "关于我们管理")
@RequestMapping("/api/aboutUs")
public class AboutUsController {

    @Resource
    public AboutUsService aboutUsService;

    @PostMapping("/addAbout")
    @ApiOperation(value = "添加关于我们")
    public ApiResult addAbout(@RequestBody AboutUsVO aboutVO){
        AboutUs about = new AboutUs();
        BeanUtils.copyProperties(aboutVO,about);
        aboutUsService.save(about);
        return ApiResult.ok("新增成功！", "头像上传成功！");
    }

    @GetMapping("/queryAbout")
    @ApiOperation(value = "查询关于我们")
    public ApiResult queryAbout() {
        Map<String ,Object> map=new HashMap<>();
        map.put("delete_flags",0);
        List<AboutUs> aboutUses = aboutUsService.listByMap(map);
        return ApiResult.success(aboutUses);
    }

    @PostMapping("/deleteAbout")
    @ApiOperation(value = "删除关于我们")
    public ApiResult deleteAbout(@RequestBody Integer id){
        aboutUsService.removeById(id);
        return ApiResult.ok("删除成功！", "头像上传成功！");
    }

    @PostMapping("/updateAbout")
    @ApiOperation(value = "修改关于我们")
    public ApiResult updateAbout(Integer id, AboutUsVO aboutVO){
        AboutUs about = new AboutUs();
        BeanUtils.copyProperties(aboutVO,about); //代替塞值
        about.setId(id);
        aboutUsService.updateById(about);
        return ApiResult.ok("修改成功！", "头像上传成功！");
    }
}
